﻿using Aribaccio;
using Aribaccio.Datum;
using BDPAutodetect.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;

namespace BDPAutodetect.DataService
{
    /// <summary>
    /// 对象关系映射配置-系统配置类
    /// </summary>
    public class TBasicSystemsConfiguration : TBaseConfiguration, IEntityTypeConfiguration<TBasicSystems>
    {
        /// 构造函数
        /// </summary>
        public TBasicSystemsConfiguration(DBConnectType argConnectionType)
            : base(argConnectionType)
        {

        }

        /// <summary>
        /// 配置映射关系
        /// </summary>
        /// <param name="builder"></param>
        public void Configure(EntityTypeBuilder<TBasicSystems> builder)
        {
            builder.ToTable("T_Basic_Systems");
            builder.Property(e => e.ID).HasColumnName("ID");
            builder.HasIndex(e => e.Name, "UQ_T_Basic_Systems").IsUnique();
            switch (this.ConnectionType)
            {
                case DBConnectType.SQLServer:
                    builder.Property(e => e.UpdateTime).HasDefaultValueSql("(getdate())");
                    break;
                case DBConnectType.PostgreSQL:
                    builder.Property(e => e.Name).HasColumnType("character varying");
                    builder.Property(e => e.Datum).HasColumnType("character varying");
                    builder.Property(e => e.DataType).HasDefaultValue(0);
                    builder.Property(e => e.UpdateTime).HasDefaultValueSql("now()").HasColumnType("timestamp without time zone");
                    break;
            }
        }
    }
}
